
package org.bridgen.lang.semantics.ast;
import java.util.*;


public class Recover extends AltRecover implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public Recover clone() throws CloneNotSupportedException {
        Recover node = (Recover)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public Recover copy() {
      try {
          Recover node = (Recover)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public Recover fullCopy() {
        Recover res = (Recover)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in PrettyPrint.jrag at line 169

    
    public void pp(StringBuffer buf) {
    	buf.append(indent());
    	if (hasWhenExpr()) {
    		buf.append("when (");
    		getWhenExpr().pp(buf);
    		buf.append(") ");
    	}
    	buf.append("find ");
    	getSitePattern().pp(buf);
    	buf.append(" where ");
    	getWhereExpr().pp(buf);
    	buf.append(" ");
    	getInsertionRule().pp(buf); 
    	buf.append(";\n");
    }

    // Declared in TypeCodeGen.jrag at line 582

	
	public void generateMethod_possibleSite(String indent, StringBuffer buf) {
		//buf.append(indent + "// Recover: ");
		//pp(buf);
		buf.append(indent + "{\n");
		if (hasWhenExpr()) {
			buf.append(indent + "if (");
			getWhenExpr().generateCode(indent, buf);
			buf.append(") {\n");
		}
		getSitePattern().generateMethod_possibleSite(indent + INDENT, buf);
		buf.append(indent + INDENT + "if (");
		getSitePattern().generateNullCheck(indent + INDENT, buf);
		buf.append(" && \n" + indent + INDENT + "  (");
		Expr expr = getWhereExpr();
		expr.generateAttrChecks(indent + INDENT + INDENT, buf);
		buf.append("\n" + indent + INDENT + "  (");
		expr.generateCode(indent + INDENT + "  ", buf);
		buf.append("))) {\n");
		getInsertionRule().generateMethod_possibleSite(indent + INDENT + INDENT, buf);
		buf.append(indent + INDENT + "}\n"); 
		if (hasWhenExpr()) {
			buf.append(indent + "}\n");
		}
		buf.append(indent + "}\n");
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 49

    public Recover() {
        super();

        setChild(new Opt(), 0);

    }

    // Declared in bridgit.ast at line 11


    // Declared in bridgit.ast line 49
    public Recover(Opt<Expr> p0, SitePattern p1, Expr p2, InsertionRule p3) {
        setChild(p0, 0);
        setChild(p1, 1);
        setChild(p2, 2);
        setChild(p3, 3);
    }

    // Declared in bridgit.ast at line 18


  protected int numChildren() {
    return 4;
  }

    // Declared in bridgit.ast at line 21

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 49
    public void setWhenExprOpt(Opt<Expr> opt) {
        setChild(opt, 0);
    }

    // Declared in bridgit.ast at line 6


    public boolean hasWhenExpr() {
        return getWhenExprOpt().getNumChild() != 0;
    }

    // Declared in bridgit.ast at line 10


     @SuppressWarnings({"unchecked", "cast"})  public Expr getWhenExpr() {
        return (Expr)getWhenExprOpt().getChild(0);
    }

    // Declared in bridgit.ast at line 14


    public void setWhenExpr(Expr node) {
        getWhenExprOpt().setChild(node, 0);
    }

    // Declared in bridgit.ast at line 17

     @SuppressWarnings({"unchecked", "cast"})  public Opt<Expr> getWhenExprOpt() {
        return (Opt<Expr>)getChild(0);
    }

    // Declared in bridgit.ast at line 21


     @SuppressWarnings({"unchecked", "cast"})  public Opt<Expr> getWhenExprOptNoTransform() {
        return (Opt<Expr>)getChildNoTransform(0);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 49
    public void setSitePattern(SitePattern node) {
        setChild(node, 1);
    }

    // Declared in bridgit.ast at line 5

    public SitePattern getSitePattern() {
        return (SitePattern)getChild(1);
    }

    // Declared in bridgit.ast at line 9


    public SitePattern getSitePatternNoTransform() {
        return (SitePattern)getChildNoTransform(1);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 49
    public void setWhereExpr(Expr node) {
        setChild(node, 2);
    }

    // Declared in bridgit.ast at line 5

    public Expr getWhereExpr() {
        return (Expr)getChild(2);
    }

    // Declared in bridgit.ast at line 9


    public Expr getWhereExprNoTransform() {
        return (Expr)getChildNoTransform(2);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 49
    public void setInsertionRule(InsertionRule node) {
        setChild(node, 3);
    }

    // Declared in bridgit.ast at line 5

    public InsertionRule getInsertionRule() {
        return (InsertionRule)getChild(3);
    }

    // Declared in bridgit.ast at line 9


    public InsertionRule getInsertionRuleNoTransform() {
        return (InsertionRule)getChildNoTransform(3);
    }

    // Declared in NameAnalysis.jrag at line 220
 @SuppressWarnings({"unchecked", "cast"})     public boolean isRecover() {
        boolean isRecover_value = isRecover_compute();
        return isRecover_value;
    }

    private boolean isRecover_compute() {  return true;  }

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

}
